mui.init({
    beforeback: function () {
        //获得列表界面的webview
        var parentOobj = plus.webview.currentWebview().opener();
        //触发列表界面的自定义事件（dataList）,从而进行数据刷新
        mui.fire(parentOobj, 'dataList');
        //返回true，继续页面关闭逻辑
        return true;
    }
});
mui.plusReady(function () {
	hideScrollBar();
    var self = plus.webview.currentWebview();
    var ebookid = self.bookid;
    var shidu_detail = new Vue({
        el: '#test_content',
        data: {
            content: '',
            vip: '',
            payway: 'wxpay',
            loginSta:0,
        },
        mounted() {
            this.init_data();
            this.updateStatus();
        },
        computed: {
            price: function () {
                if (this.vip > 1) {
                    return this.content.vipprice;
                } else {
                    return this.content.novipprice;
                }
            }
        },
        methods: {
            init_data: function () {
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/ebook/index/get_shidu/bookid/'+ebookid,
                    dataType: 'json',
                    type: 'get',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    async: true,
                    success: function (data) {
                        if (data.code == 1) {
                            shidu_detail.content = data.data
                        } else {
                            mui.toast(data.msg, {duration: '200',type: 'div'});
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('加载失败!', {duration: '200',type: 'div'});
                    },
                    complete:function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            updateStatus:function(){
                var api_host = plus.storage.getItem('HOST_URL');
                var self = this;
                mui.ajax({
                    url: api_host + '/api/linxuan/user/checkLoginStatus',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            self.loginSta = 1;
                            self.vip = msg.data.vip;
                        } else {
                            self.loginSta = 0;
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('登录状态请求失败请重试', {duration: '300'});
                    }
                });
            },
            open_buy_book: function () {
                if(this.loginSta == 0){
                    mui.toast('您还未登陆，请登录后再试!', {duration: '2000',type: 'div'});
                }else{
                    $('.popMask').show();
                    $('.popPay').animate({
                        'bottom': '0%'
                    }, 300).show();
                }
            },
            close_layer: function () {
                $('.popMask').hide();
                $('.popPay').animate({
                    'bottom': '-100%'
                }, 300).hide(0);
            },
            choice_pay_type: function (type) {
                this.payway = type;
            },
            open_zhifu: function () {
                var goodsInfo = {
                    'id': ebookid,
                };
                new pay().start('ebook',this.payway,1,goodsInfo);

            }
        }
    })
})
